<!--
  * 主表，用于存储商户的进件信息，包括微信和支付宝的进件状态及相关数据。
  *
  * @Author:    zzb
  * @Date:      2025-02-25 06:40:36
  * @Copyright  zzb
-->
<template>
  <!---------- 查询表单form begin ----------->
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="商户名称" class="smart-query-form-item">
        <a-input style="width: 200px" v-model:value="queryForm.companyName" placeholder="商户名称" />
      </a-form-item>
      <!-- <a-form-item label="商户类型" class="smart-query-form-item">
        <SmartEnumSelect width="200px" v-model:value="queryForm.subjectType" enumName="ZZB_SUBJECT_TYPE_ENUM" placeholder="商户类型" />
      </a-form-item> -->
      <a-form-item label="联系人" class="smart-query-form-item">
        <a-input style="width: 200px" v-model:value="queryForm.name" placeholder="联系人" />
      </a-form-item>
      <!-- <a-form-item label="审核状态" class="smart-query-form-item">
        <SmartEnumSelect width="200px" v-model:value="queryForm.status" enumName="ZZB_REGISTAUDIT_STATUS_ENUM" placeholder="审核状态" />
      </a-form-item> -->
      <a-form-item label="通道类型" class="smart-query-form-item">
        <SmartEnumSelect width="200px" v-model:value="queryForm.type" enumName="ZZB_CHANNEL_TYPE_ENUM" placeholder="通道类型" />
      </a-form-item>
      <a-form-item class="smart-query-form-item">
        <a-button type="primary" @click="onSearch">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="resetQuery" class="smart-margin-left10">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
      </a-form-item>
    </a-row>
  </a-form>
  <!---------- 查询表单form end ----------->

  <a-card size="small" :bordered="false" :hoverable="true">
    <!---------- 表格操作行 begin ----------->
    <a-row class="smart-table-btn-block">
      <div class="smart-table-operate-block"></div>
      <div class="smart-table-setting-block">
        <!-- <TableOperator v-model="columns" :tableId="null" :refresh="queryData" /> -->
      </div>
    </a-row>
    <!---------- 表格操作行 end ----------->

    <!---------- 表格 begin ----------->
    <a-table size="small" :dataSource="tableData" :columns="columns" rowKey="id" bordered :loading="tableLoading" :pagination="false">
      <template #bodyCell="{ record, column }">
        <!-- <template v-if="column.dataIndex === 'status'">
          <a-tag :color="statusTypeColorArray[text]">
            {{ $smartEnumPlugin.getDescByValue('ZZB_REGISTAUDIT_STATUS_ENUM', text) }}
          </a-tag>
        </template> -->
        <template v-if="column.dataIndex === 'action'">
          <a-button @click="view(record)" type="link">详情</a-button>
        </template>
      </template>
    </a-table>
    <!---------- 表格 end ----------->

    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageNo"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="queryData"
        @showSizeChange="queryData"
        :show-total="(total) => `共${total}条`"
      />
    </div>
  </a-card>
</template>
<script setup>
  import { onMounted, reactive, ref, getCurrentInstance } from 'vue'
  import { businessApplicationApi } from '/@/api/business/b-operation/expand/business-application-api.js'
  import { PAGE_SIZE_OPTIONS } from '/@/constants/common-const'
  import { smartSentry } from '/@/lib/smart-sentry'
  import TableOperator from '/@/components/support/table-operator/index.vue'
  import SmartEnumSelect from '/@/components/framework/smart-enum-select/index.vue'
  import dayjs from 'dayjs'
  //import FilePreview from '/@/components/support/file-preview/index.vue'; // 图片预览组件
  const { proxy } = getCurrentInstance()

  // ---------------------------- 表格列 ----------------------------

  const columns = ref([
    {
      title: '序号',
      dataIndex: 'index',
      width: 60,
      customRender: ({ index }) => {
        return (queryForm.pageNo - 1) * queryForm.pageSize + index + 1
      },
    },
    {
      title: '商户名称',
      dataIndex: 'companyName',
      ellipsis: true,
    },
    {
      title: '商户联系人',
      dataIndex: 'name',
      ellipsis: true,
    },
    // {
    //   title: '商户类型',
    //   dataIndex: 'subjectType',
    //   // customRender: ({ text }) => {
    //   //   return selectDictLabel(proxy.$smartEnumPlugin.getValueDescList('AUTH_BUSINESS_ENUM'), text)
    //   // },
    //   ellipsis: true,
    // },
    {
      title: '所属上级',
      dataIndex: 'oAgentName',
      ellipsis: true,
    },
    {
      title: '支付通道',
      dataIndex: 'channelType',
      customRender: ({ text }) => {
        return selectDictLabel(proxy.$smartEnumPlugin.getValueDescList('ZZB_CHANNEL_TYPE_ENUM'), text)
      },
      ellipsis: true,
    },
    {
      title: '进件审核状态',
      dataIndex: 'channelType',
      customRender: ({ text }) => {
        return selectDictLabel(proxy.$smartEnumPlugin.getValueDescList('ZZB_CHANNEL_TYPE_ENUM'), text)
      },
      ellipsis: true,
    },
    {
      title: '费率',
      dataIndex: 'status',
      ellipsis: true,
    },
    {
      title: '签约账户',
      dataIndex: 'status',
      ellipsis: true,
    },
    {
      title: '结算账号',
      dataIndex: 'status',
      ellipsis: true,
    },
    {
      title: '签约时间',
      dataIndex: 'uTime',
      customRender: (column) => dayjs(column.text).format('YYYY-MM-DD HH:mm'),
      ellipsis: true,
    },
    {
      title: '创建时间',
      dataIndex: 'uTime',
      customRender: (column) => dayjs(column.text).format('YYYY-MM-DD HH:mm'),
      ellipsis: true,
    },
    // {
    //   title: '审核状态',
    //   dataIndex: 'status',
    //   ellipsis: true,
    // },
    {
      title: '审核失败原因',
      dataIndex: 'status',
      ellipsis: true,
    },
    {
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
      width: 80,
    },
  ])

  // ---------------------------- 查询数据表单和方法 ----------------------------

  const queryFormState = {
    companyName: undefined, //商户名称
    subjectType: undefined, //商户类型
    name: undefined, //联系人
    status: undefined, //审核状态
    type: undefined, //通道类型
    pageNo: 1,
    pageSize: 10,
  }
  // 查询表单form
  const queryForm = reactive({ ...queryFormState })
  // 表格加载loading
  const tableLoading = ref(false)
  // 表格数据
  const tableData = ref([])
  // 总数
  const total = ref(0)

  // 重置查询条件
  function resetQuery() {
    let pageSize = queryForm.pageSize
    Object.assign(queryForm, queryFormState)
    queryForm.pageSize = pageSize
    queryData()
  }

  // 搜索
  function onSearch() {
    queryForm.pageNo = 1
    queryData()
  }

  // 查询数据
  async function queryData() {
    tableLoading.value = true
    try {
      let queryResult = await businessApplicationApi.queryPage(queryForm)
      tableData.value = queryResult.data
      total.value = queryResult.total
    } catch (e) {
      smartSentry.captureError(e)
    } finally {
      tableLoading.value = false
    }
  }

  // 查看详情
  function view(record) {
    console.log('详情', record)
  }
  onMounted(queryData)
</script>
